package servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletException;
import java.io.IOException;

import bean.Log;
import bean.User;
import dao.LogManagerDao;
import dao.LogManagerDaoImpl;
import dao.MailManagerDao;
import dao.MailManagerDaoImpl;
import dao.UserManagerDao;
import dao.UserManagerDaoImpl;

public class delUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
		request.setCharacterEncoding("UTF-8");
		String id = request.getParameter("userid") ;
		LogManagerDao logdao =new LogManagerDaoImpl();
		Log log=new Log();
		HttpSession session = request.getSession();
		User user1=(User) session.getAttribute("user");
		UserManagerDao userdao = new  UserManagerDaoImpl();
		if(userdao.deleteUser(id)==true){
			log.setExcution("删除用户");
			log.setExcutor(user1.getUser_id());
			log.setState(true);
			logdao.addLog(log);
		}
		else{
			log.setExcution("删除用户");
			log.setExcutor(user1.getUser_id());
			log.setState(false);
			logdao.addLog(log);
		}
		
		request.getRequestDispatcher("userManage.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
